import HTTP from '@/libs/https'
import {
    BASE_URL
} from '@/configs/config'
const {
    axiosGet,
    axiosPost
} = new HTTP();

function http(params) {
    let [method, url] = params.split(' ');
    return function (data = {}, options = {}) {
        return new Promise((resolve, reject) => {
            let params = {
                url,
                data,
                success(data) {
                    resolve(data);
                },
                error(err) {
                    reject(err);
                },
                ...(options || {})
            }

            if (method === 'GET') {
                axiosGet(params);
            } else if (method === 'POST') {
                axiosPost(params);
            }
        })
    }
}
let api = {
    getSongListCategories: `POST ${BASE_URL}/api/classify/list`,
    getSongLists: `POST ${BASE_URL}/api/songlist/find`,
    getSongListDetails: `POST ${BASE_URL}/api/songlist/detail`,
    getLyricByIds: `POST ${BASE_URL}/api/MusicLyric/find`,
    findMusicByName: `POST ${BASE_URL}/api/music/findbyname`,
    carouselRand: `POST ${BASE_URL}/api/carousel/findrand`,
    songlistRand: `POST ${BASE_URL}/api/songlist/findrand`,
    musicRand: `POST ${BASE_URL}/api/music/findrand`,

};

for (let key in api) {
    api[key] = http(api[key]);
}

export default api;

// export default class Model extends HTTP {
//     GET_GetMusicPlays(params) {
//         return new Promise((resolve, reject) => {
//             this.axiosGet({
//                 url: API.GET_GetMusicPlay,
//                 data: params,
//                 success(data) {
//                     resolve(data);
//                 },
//                 error(err) {
//                     reject(err);
//                 }
//             });
//         });
//     }
// }